package com.ding.courier;

public class Courier {

    private String targetHost;

    private Integer targetPort;

    private String commanderHost;

    private Integer commanderPort;

    private int pollingIntervalStart = 1000;

    private int pollingIntervalIncrease = 500;

    private int maxPollingInterval = 10000;

    private String password = "mynat";

    public String getTargetHost() {
        return targetHost;
    }

    public void setTargetHost(String targetHost) {
        this.targetHost = targetHost;
    }

    public int getTargetPort() {
        return targetPort;
    }

    public void setTargetPort(int targetPort) {
        this.targetPort = targetPort;
    }

    public String getCommanderHost() {
        return commanderHost;
    }

    public void setCommanderHost(String commanderHost) {
        this.commanderHost = commanderHost;
    }

    public int getCommanderPort() {
        return commanderPort;
    }

    public void setCommanderPort(int commanderPort) {
        this.commanderPort = commanderPort;
    }

    public int getPollingIntervalStart() {
        return pollingIntervalStart;
    }

    public void setPollingIntervalStart(int pollingIntervalStart) {
        this.pollingIntervalStart = pollingIntervalStart;
    }

    public int getPollingIntervalIncrease() {
        return pollingIntervalIncrease;
    }

    public void setPollingIntervalIncrease(int pollingIntervalIncrease) {
        this.pollingIntervalIncrease = pollingIntervalIncrease;
    }

    public int getMaxPollingInterval() {
        return maxPollingInterval;
    }

    public void setMaxPollingInterval(int maxPollingInterval) {
        this.maxPollingInterval = maxPollingInterval;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    private CommanderHolder commanderHolder;

    public void start() throws Exception {

        if (targetHost == null) {
            throw new RuntimeException("目标主机不能为空");
        }

        if (targetPort == null) {
            throw new RuntimeException("目标端口不能为空");
        }

        if (commanderHost == null) {
            throw new RuntimeException("调度中心主机不能为空");
        }

        if (commanderPort == null) {
            throw new RuntimeException("调度中心端口不能为空");
        }

        CPool cPool = new CPool();

        cPool.setTargetHost(targetHost);

        cPool.setTargetPort(targetPort);
        commanderHolder = new CommanderHolder();

        commanderHolder.setCommanderHost(this.commanderHost);

        commanderHolder.setCommanderPort(this.commanderPort);

        commanderHolder.setStartPollingInterval(this.pollingIntervalStart);

        commanderHolder.setPollingIntervalIncrease(this.pollingIntervalIncrease);

        commanderHolder.setMaxPollingInterval(this.maxPollingInterval);

        cPool.setCommanderHolder(commanderHolder);

        commanderHolder.setPassword(this.password);

        commanderHolder.setPool(cPool);

        commanderHolder.start();

    }

    public void stop() {
        this.commanderHolder.stop();
    }


}
